package acm.集美大学;

import java.util.Scanner;

public class J解压文本 {
    static int n;
    static String[] list;
    static boolean[] vis;   //存储正在解压的数据
    static boolean[] dp;    //存储解压过的数据
    static Scanner sc=new Scanner(System.in);
    public static void main(String[] args) {
        n = sc.nextInt();
        sc.nextLine();
        list=new String[n+1];
        vis=new boolean[n+1];
        dp=new boolean[n+1];
        for (int i = 1; i <= n; i++) {
            String line = sc.nextLine();
            while (line.charAt(line.length()-1)!='#'){
                line=line+sc.nextLine();
            }
            list[i]=line;
        }

        String pares = "#";
        try {
            pares=pares(1);
        }catch (Exception e){}
        System.out.println(pares);
    }
    static int maxN= (int) 1e6;

    /**
     * 解析i号字符串
     */
    public static String pares(int i){
        if (i>n||i<1) return "";
        if (vis[i]) throw new RuntimeException();
        if (dp[i])return list[i];
        vis[i]=true;
        char[] chars = list[i].toCharArray();
        StringBuilder builder=new StringBuilder();
        for (int j = 0; j < chars.length-1; j++) {
            if (chars[j]=='*'){
                builder.append(pares(chars[j+1]-'0'));
                j++;
            }else {
                builder.append(chars[j]);
            }
            if (builder.length()>maxN) throw new RuntimeException();
        }
        dp[i]=true;
        list[i]=builder.toString();
        vis[i]=false;
        return list[i];
    }
}
